package com.wenhai.spring.bean.lifecycle;

import com.wenhai.xiaomage.spring.ioc.overview.dependency.domain.User;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

public class UserHolder implements BeanNameAware,BeanClassLoaderAware, BeanFactoryAware,EnvironmentAware,SmartInitializingSingleton,AutoCloseable {

    private User user;

    private ClassLoader classLoader;

    private BeanFactory beanFactory;

    private String beanName;

    private String description;

    private Environment environment;

    public UserHolder(User user) {
        this.user = user;
    }

    public UserHolder() {

    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public ClassLoader getClassLoader() {
        return classLoader;
    }

    public void setClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public String getBeanName() {
        return beanName;
    }

    public Environment getEnvironment() {
        return environment;
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName = name;
    }


    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
    @Override
    public String toString() {
        return "UserHolder{" +
                "user=" + user +
                ", classLoader=" + classLoader +
                ", beanFactory=" + beanFactory +
                ", beanName='" + beanName + '\'' +
                ", description='" + description + '\'' +
                ", environment=" + environment +
                '}';
    }

    @Override
    public void afterSingletonsInstantiated() {

    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public void close() throws Exception {
        System.out.println("close 方法被调用");
    }


}
